package cn.gjxblog.service.impl;

import cn.gjxblog.common.model.PageCondition;
import cn.gjxblog.dao.UserMsgMapper;
import cn.gjxblog.model.entity.UserMsg;
import cn.gjxblog.model.entity.UserMsgExample;
import cn.gjxblog.service.UserMsgService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author gjx
 * @version v1.0
 * @Description
 * @date 2019/4/26 10:55
 */
@Service
public class UserMsgServiceImpl implements UserMsgService {

    @Autowired
    private UserMsgMapper userMsgMapper;

    @Override
    public void addUserMsg(UserMsg userMsg) {
        userMsgMapper.insert(userMsg);
    }

    @Override
    public PageInfo<UserMsg> queryUserMsgByUserId(String userId, PageCondition pageCondition) {
        UserMsgExample userMsgExample = new UserMsgExample();
        userMsgExample.createCriteria().andUserIdEqualTo(userId);
        List<UserMsg> userMsgs = userMsgMapper.selectByExample(userMsgExample);
        PageInfo<UserMsg> userMsgPageInfo = new PageInfo<>(userMsgs);

        return userMsgPageInfo;

    }

    @Override
    public PageInfo<UserMsg> queryUserMsgByAgentId(String agentId, PageCondition pageCondition) {
        UserMsgExample userMsgExample = new UserMsgExample();
        userMsgExample.createCriteria().andAgentIdEqualTo(agentId);
        List<UserMsg> userMsgs = userMsgMapper.selectByExample(userMsgExample);
        PageInfo<UserMsg> userMsgPageInfo = new PageInfo<>(userMsgs);

        return userMsgPageInfo;

    }

}
